package com.ima.controller;

import com.ima.repository.ResumeRepository;
import com.ima.utils.CookieUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;


@Controller
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private ResumeRepository resumeRepository;



    @RequestMapping(value = "/view")
    public String view(ModelMap modelMap) {
      return  "view";
    }
    @RequestMapping(value = "/submit")
    public String view(ModelMap modelMap, String userName, String password, HttpServletResponse response) {
        if (!"admin".equals(userName)||!"admin".equals(password)){
            CookieUtil.addCookie(response,"login","false");
            return "failView";
        }
        modelMap.addAttribute("resumes",resumeRepository.findAll());
        CookieUtil.addCookie(response,"login","success");
        return  "listView";
    }
}
